package com.windoent.yugioh.adapter.brvah;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.windoent.yugioh.R;
import com.windoent.yugioh.bean.OnGoingHasEndLunBean;
import com.windoent.yugioh.utils.BaseMethod;
import com.windoent.yugioh.utils.SimpleUtils;
import com.windoent.yugioh.widget.RoundImageView;

/**
 * author : robert
 * date   : 2021/5/6 15:26
 * desc   :
 */
public class SaiGuoTitleContentAdapter extends BaseQuickAdapter<OnGoingHasEndLunBean.DataBean.AgainstResultOffBean.ResultBean, BaseViewHolder> {

    public SaiGuoTitleContentAdapter() {
        super(R.layout.item_saiguo_title, null);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, OnGoingHasEndLunBean.DataBean.AgainstResultOffBean.ResultBean item) {
        helper.setText(R.id.tv_name_left, BaseMethod.notNullDefaultValueNull(item.getAnickname()))
                .setText(R.id.tv_name_right, BaseMethod.notNullDefaultValueNull(item.getBnickname()));

        RoundImageView iv_avatar_left = helper.getView(R.id.iv_avatar_left);
        RoundImageView iv_avatar_right = helper.getView(R.id.iv_avatar_right);
        SimpleUtils.loadImageForView(getContext(), iv_avatar_left, item.getAavatar(), R.drawable.img_official_avatar_android);
        SimpleUtils.loadImageForView(getContext(), iv_avatar_right, item.getBavatar(), R.drawable.img_official_avatar_android);

        ImageView iv_sucess_bg_left_huangguan = helper.getView(R.id.iv_sucess_bg_left_huangguan);
        ImageView iv_sucess_bg_right_huangguan = helper.getView(R.id.iv_sucess_bg_right_huangguan);
        TextView tv_name_left = helper.getView(R.id.tv_name_left);
        ImageView tv_result_left = helper.getView(R.id.tv_result_left);
        TextView tv_name_right = helper.getView(R.id.tv_name_right);
        ImageView tv_result_right = helper.getView(R.id.tv_result_right);
        int aResult = item.getAresult();//1胜，2平，3负，4双负
        int bResult = item.getBresult();
        boolean aVictory = aResult == 1 && bResult == 3;
        boolean bVictory = bResult == 1 && aResult == 3;
        showUi(aVictory, bVictory, iv_avatar_left, iv_avatar_right, iv_sucess_bg_left_huangguan, iv_sucess_bg_right_huangguan, tv_name_left, tv_name_right, tv_result_left, tv_result_right);
    }

    private void showUi(boolean aVictory, boolean bVictory, RoundImageView iv_avatar_left, RoundImageView iv_avatar_right, ImageView iv_sucess_bg_left_huangguan, ImageView iv_sucess_bg_right_huangguan, TextView tv_name_left, TextView tv_name_right, ImageView tv_result_left, ImageView tv_result_right) {
        if (aVictory && !bVictory) {
            iv_avatar_left.setShape(false);
            iv_avatar_right.setShape(true);
            iv_sucess_bg_left_huangguan.setVisibility(View.VISIBLE);
            iv_sucess_bg_right_huangguan.setVisibility(View.INVISIBLE);
            tv_name_left.setSelected(true);
            tv_result_left.setSelected(true);
            tv_name_right.setSelected(false);
            tv_result_right.setSelected(false);
        } else if (bVictory && !aVictory) {
            iv_avatar_left.setShape(true);
            iv_avatar_right.setShape(false);
            iv_sucess_bg_left_huangguan.setVisibility(View.INVISIBLE);
            iv_sucess_bg_right_huangguan.setVisibility(View.VISIBLE);
            tv_name_left.setSelected(false);
            tv_result_left.setSelected(false);
            tv_name_right.setSelected(true);
            tv_result_right.setSelected(true);
        } else {
            iv_avatar_left.setShape(true);
            iv_avatar_right.setShape(true);
            iv_sucess_bg_left_huangguan.setVisibility(View.INVISIBLE);
            iv_sucess_bg_right_huangguan.setVisibility(View.INVISIBLE);
            tv_name_left.setSelected(false);
            tv_result_left.setSelected(false);
            tv_name_right.setSelected(false);
            tv_result_right.setSelected(false);
        }
    }
}